#include "process.h"

#include <unistd.h>
#include <string.h>

#define NUM 101
#define STYLE '='

static int count = 0;

void FflushProcess(double current, double total)
{
   char buffer[NUM];
   memset(buffer, 0, sizeof(buffer));
   const char* label = "|/-\\";

   int num = (int)((current * 100) / total);

   for(int i = 0; i < num; i++)
   {
       buffer[i] = STYLE;
   }

   double rate = current * 100 / total;
    printf("[%-100s][%.2lf%%][%c]\r", buffer, rate, label[count % strlen(label)]);
    count++;
    fflush(stdout);
}
void process_v1()
{
    char buffer[NUM];
    memset(buffer, 0, sizeof(buffer));
    const char* label = "|/-\\" ;
    int count = 0;
    while(count <= 100)
    {
        printf("[%-100s][%d%%][%c]\r", buffer, count, label[count % strlen(label)]);
        fflush(stdout);
        buffer[count] = STYLE;
        count++;
        usleep(50000);
    }
    printf("\n");
}
